package org.jeecg.modules.classrooms.classroomsUse.service.impl;


import com.baomidou.mybatisplus.core.conditions.Wrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import org.jeecg.modules.classrooms.classrooms.entity.Classrooms;
import org.jeecg.modules.classrooms.classrooms.mapper.ClassroomsMapper;
import org.jeecg.modules.classrooms.classroomsUse.entity.ClassroomsUse;
import org.jeecg.modules.classrooms.classroomsUse.mapper.ClassroomsUseMapper;
import org.jeecg.modules.classrooms.classroomsUse.service.IClassroomsUseService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;

import java.io.Serializable;
import java.util.Collection;

/**
 * @Description: classrooms_use
 * @Author: jeecg-boot
 * @Date:   2020-05-22
 * @Version: V1.0
 */
@Service
public class ClassroomsUseServiceImpl extends ServiceImpl<ClassroomsUseMapper, ClassroomsUse> implements IClassroomsUseService {

    @Autowired
    private ClassroomsMapper classroomsMapper;

    @Override
    public IPage<ClassroomsUse> page(IPage<ClassroomsUse> page, Wrapper<ClassroomsUse> queryWrapper) {
        IPage<ClassroomsUse> page1 = super.page(page, queryWrapper);
        page1.getRecords().forEach(classroomsUse -> {
            Classrooms classrooms = classroomsMapper.selectById(classroomsUse.getClassroomsId());
            classroomsUse.setClassroomsNumber(classrooms.getClassroomsNumber());
        });

        return page1;
    }


    @Override
    public boolean removeByIds(Collection<? extends Serializable> idList) {
        idList.forEach(id ->{
            ClassroomsUse classroomsUse = baseMapper.selectById(id);
            String classroomsId = classroomsUse.getClassroomsId();
            Classrooms classrooms = classroomsMapper.selectById(classroomsId);
            classrooms.setClassroomsStatus("1");
            classroomsMapper.updateById(classrooms);
        });
        return super.removeByIds(idList);
    }

    @Override
    public boolean removeById(Serializable id) {
        ClassroomsUse classroomsUse = baseMapper.selectById(id);
        String classroomsId = classroomsUse.getClassroomsId();
        Classrooms classrooms = classroomsMapper.selectById(classroomsId);
        classrooms.setClassroomsStatus("1");
        classroomsMapper.updateById(classrooms);
        return super.removeById(id);
    }
}
